
const db = require('../../providers/dataAccess');
const treeHelper = require('../../helpers/treeHelper');

const AppService = function () {
    const _getConfig = async (appId) =>{
        let szSql = "SELECT * FROM app_configs WHERE appId = ?";
        let ret = await db.info.query(szSql, [appId]);
        return ret;
    };

    const _getCMSMenus = async () => {
        let szSql = "SELECT * FROM cms_menus WHERE status = 1 ORDER BY parentId ASC,sequence ASC";
        let res = await db.sys.query(szSql);
        let menus = treeHelper.buildTree(res, "id", "parentId", "children");
        return menus;
    };

    return {
        getConfig: _getConfig,
        getCMSMenus: _getCMSMenus
    }

}();

module.exports = AppService;
